package com.kokoiko;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TableRow;

public class Friends extends Activity implements OnClickListener {

	final static String FACEBOOK = "Facebook";
	final static String TWITTER = "Twitter";
	final static String CONTACT = "Contact";

	TableRow contact;
	TableRow twitter;
	TableRow facebook;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.friends);

		contact = (TableRow) findViewById(R.id.contact);
		twitter = (TableRow) findViewById(R.id.twiiter);
		facebook = (TableRow) findViewById(R.id.facebook);

		contact.setOnClickListener(this);
		twitter.setOnClickListener(this);
		facebook.setOnClickListener(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		Intent intent;
		switch (item.getItemId()) {
		case R.id.home:
			if (!this.getClass().getName().equals(Home.class.getName())) {
				intent = new Intent(this, Home.class);
				startActivity(intent);
			}
			break;
		case R.id.friends:
			if (!this.getClass().getName().equals(Friends.class.getName())) {
				intent = new Intent(this, Friends.class);
				startActivity(intent);
			}
			break;
		case R.id.map:
			if (!this.getClass().getName().equals(Map.class.getName())) {
				intent = new Intent(this, Map.class);
				startActivity(intent);
			}
			break;
		case R.id.allkokoiko:
			if (!this.getClass().getName().equals(AllKokoiko.class.getName())) {
				intent = new Intent(this, AllKokoiko.class);
				startActivity(intent);
			}
			break;
		case R.id.message:
			if (!this.getClass().getName().equals(Message.class.getName())) {
				intent = new Intent(this, Message.class);
				startActivity(intent);
			}
			break;
		}
		return true;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

		if (v == contact) {
			searchFriend(CONTACT);
		}
		if (v == twitter) {
			searchFriend(TWITTER);
		}
		if (v == facebook) {
			searchFriend(FACEBOOK);
		}
	}

	public void searchFriend(String from) {
		Intent intent = new Intent(this, FriendList.class);
		intent.putExtra("title", from);
		startActivity(intent);
	}
}
